/*
 * @Author: Setsuna
 * @Email: setsuna.xyz@qq.com
 * @FilePath: \src\pages\DailyRecord\DailyRecordControl\index.tsx
 * @Date: 2022-12-05 10:44:43
 * @LastEditTime: 2023-05-17 15:10:05
 * @LastEditors: Setsuna
 */
import React, { Component } from 'react'
import { RouteComponentProps } from 'react-router-dom'
import { UdPage, UdPageHeader, udConfigProvider } from '@/lib'
import { BackTop, Tabs } from 'antd'

import OperateLog from './OperateLog'
import CheckLog from './CheckLog'

import './style.scss'

import udMainStore from '@/store/UdMain'

const { TabPane } = Tabs

enum ETypeTabs {
  // 手工盘点控制
  OPERATE_LOG = '1',
  // 配额上限控制
  CHECK_LOG = '2',
}

export default class GeneralConfigPage extends Component<GeneralConfigPageProps, GeneralConfigPageState> {
  private brandList = udMainStore.brandList
  private pageContainer = udConfigProvider.ui.getPageContainer()
  public typeTabs = [
    {
      value: ETypeTabs.OPERATE_LOG,
      title: '操作日志',
    },
    {
      value: ETypeTabs.CHECK_LOG,
      title: '库存盘点日志',
    },
  ]
  constructor(props) {
    super(props)
    this.state = {
      title: '操作日志',
      brandCompanies: [],
      controlType: ETypeTabs.OPERATE_LOG,
    }
  }

  componentDidMount() {
    // this.getBrandCompanyList()
  }

  render() {
    return (
      <UdPage className="detail-page general-config-page">
        <UdPageHeader title={this.state.title} affixProps={{ target: () => this.pageContainer }} />
        <Tabs defaultActiveKey={ETypeTabs.OPERATE_LOG} onChange={this.tabsChange}>
          {this.typeTabs.map(({ title, value }) => (
            <TabPane tab={title} key={value}>
              {this.state.controlType == value && this.getRenderTabCon()}
            </TabPane>
          ))}
        </Tabs>
        {this.pageContainer && <BackTop target={() => this.pageContainer} visibilityHeight={100} />}
      </UdPage>
    )
  }

  public query = () => {}

  public tabsChange = key => {
    const controlType = key
    this.setState({
      controlType,
    })
  }

  public getRenderTabCon = () => {
    const { controlType } = this.state
    if (controlType === ETypeTabs.OPERATE_LOG) {
      return <OperateLog />
    } else if (controlType === ETypeTabs.CHECK_LOG) {
      return <CheckLog />
    }
  }
}

interface GeneralConfigPageProps extends RouteComponentProps {}

interface GeneralConfigPageState {
  title: string
  brandCompanies: { value: string; title: string }[]
  controlType?: string
}
